package functional;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
import utils.Log4Test;

import java.util.concurrent.TimeUnit;

/**
 * Created by с246 on 25.06.2014.
 */
public class ProductFilter {
    public static WebDriver driver;

    @DataProvider
    public Object[][] filters() {
        return new Object[][] {
                new Object[] {"some_name"},
        };
    }

    @BeforeSuite
    public void initEnv()
    {
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("http://rozetka.com.ua/");
    }

    @Test (dataProvider = "filters")
    public void numberOfFilteredElemantsTest(String filterName)
    {
        Log4Test.info("message");


        WebDriverWait wait = new WebDriverWait(driver, 30);

        Actions builder = new Actions(driver);
        builder.moveToElement(driver.findElement(By.id("computers-notebooks")));
        builder.perform();

        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a/ancestor::a[contains(@*,'notebooks/c80004'])")));
        driver.findElement(By.xpath("//a[contains(@*,'http://rozetka.com.ua/notebooks/c80004'])")).click();
        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@href,'notebooks'])")));
        driver.findElement(By.xpath("//a[contains(@href,'notebooks'])")).click();
    }

    @AfterSuite
    public void shutEnv()
    {
        if (driver != null)
            driver.quit();
    }
}
